package com.dgut.doctorservice.controller;


import com.dgut.commonutils.Result;
import com.dgut.doctorservice.entity.DepartmentInfo;
import com.dgut.doctorservice.entity.department.OneDepartment;
import com.dgut.doctorservice.service.DepartmentInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dgut
 * @since 2021-09-08
 */
@RestController
@RequestMapping("/doctorservice/department")
@CrossOrigin
@Api("科室控制器")
public class DepartmentInfoController {
    @Autowired
    private DepartmentInfoService departmentInfoService;

    @ApiOperation("通过上传excel进行科室的添加")
    //添加科室分类，读取上传到这里的文件
    @PostMapping("addDepartment")
    public Result addDepartment(MultipartFile file){
        departmentInfoService.saveDepartments(file,departmentInfoService);
        return Result.succ();
    }

    @ApiOperation("获取所有科室在管理员页面进行树形显示")
    @GetMapping("getAllDepartments")
    public Result getAllDepartments(){
        List<OneDepartment> list=departmentInfoService.getAllOneAndTwoDepartments();
        if (list.size()==0){
            return Result.succ().message("暂时没有科室");
        }else{
            return Result.succ().data("list",list);
        }

    }

    @ApiOperation("添加医生时选择医生科室，使用二级科室id")
    @GetMapping("getSecondDepartment")
    public Result getSecondDepartments(){
        List<DepartmentInfo> departmentInfos = departmentInfoService.secondDepartment();
        if (departmentInfos.size()==0){
            return Result.succ().message("暂时没有二级科室");
        }else {
            return Result.succ().data("secondList",departmentInfos);
        }
    }

}

